import {
    Component,
    Injector,
    ViewEncapsulation,
    ViewChild,
    AfterViewInit
} from '@angular/core';
import { Http } from '@angular/http';
import { AppComponentBase } from '@shared/common/app-component-base';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import {
    WorkshopDomainServiceProxy,
    ComponentDomainDto
} from '@shared/service-proxies/service-proxies';

@Component({
    templateUrl: './act-domain.component.html',
    styleUrls: ['./act-domain.component.less'],
    encapsulation: ViewEncapsulation.None,
    animations: [appModuleAnimation()]
})
export class ActDomainComponent extends AppComponentBase
    implements AfterViewInit {
    @ViewChild('dataTable') dataTable: Table;
    @ViewChild('paginator') paginator: Paginator;

    anyncing = false;

    domains = Array<ComponentDomainDto>();

    //currentFlow = Array<ComponentInfoDto>();

    constructor(
        injector: Injector,
        private _workshopDomainServiceProxy: WorkshopDomainServiceProxy
    ) {
        super(injector);
    }

    ngAfterViewInit(): void {
        this.getComponentsConfigs();
    }

    getComponentsConfigs() {
        this.primengTableHelper.showLoadingIndicator();

        this._workshopDomainServiceProxy
            .getAllComponentDomains()
            .subscribe(result => {
                this.domains = result;
                this.primengTableHelper.hideLoadingIndicator();
            });
    }

    getKeys(item) {
        let items = this.domains.filter(el => {
            return el === item;
        });

        if (items.length >= 0) {
            return items[0].componentInfoDtos;
        }
        return null;
    }
}
